package com.chixing.day08.OrderSystem;

public class OrderBusiness {
    public void saveOrder(OrderInterf order) {
        while (order.getOrderNum() > 1000) {
            OrderInterf newOrder = null; //创建新订单
            if (order instanceof PersonalOrder) {
                PersonalOrder p2 = new PersonalOrder();
                PersonalOrder p1 = (PersonalOrder) order;  //赋值
                p2.setCustomerName(p1.getCustomerName());
                p2.setProductId(p1.getProductId());
                p2.setOrderNum(1000);
                newOrder = p2;
            } else if (order instanceof EmptyOrder) {
                EmptyOrder e2 = new EmptyOrder();
                EmptyOrder e1 = (EmptyOrder) order;
                e2.setEmptyName(e1.getEmptyName());
                e2.setEmptyId(e1.getEmptyId());
                e2.setOrderNum(1000);
                newOrder = e2;
            }
            order.setOrderNum(order.getOrderNum() - 1000);
            System.out.println("拆分订单 ==> " + newOrder);
        }
        System.out.println("订单:==> " + order);
    }
}
